<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        div {
            width: 100px;
            height: 100px;
            background:linear-gradient(to right,red,blue);
        }
    </style>
</head>
<body>
    <!-- 通过对document设置事件  通过事件捕获来获得触摸的元素 -->
    <div></div>
    <div></div>
    <script>
    var startX,startY,moveX,moveY,distanceX,distanceY;
    // 开始触摸
    document.addEventListener("touchstart",function(e){
        startX = e.targetTouches[0].clientX;
        startY = e.targetTouches[0].clientY;
    }); 
    // 滑动
    document.addEventListener("touchmove",function(e){
        moveX = e.targetTouches[0].clientX;
        moveY = e.targetTouches[0].clientY;
        distanceX = moveX - startX;
        distanceY = moveY - startY;
        e.target.style.transform = "translate("+distanceX+"px,"+distanceX+"px)";
    });
    // 触摸结束
    document.addEventListener("touchend",function(e){
    });
    </script>
    
</body>
</html>